package c.c.a;

import android.app.Activity;
import android.app.Application.ActivityLifecycleCallbacks;
import android.os.Bundle;
import android.text.TextUtils;
import c.b.a.a.a;
import com.bytedance.embedapplog.IPicker;
import java.util.HashSet;

public class n1 implements ActivityLifecycleCallbacks {
    public static int b;
    public static a0 c;
    public static long d;
    public static String e;
    public static Object f;
    public static final HashSet<Integer> g = new HashSet(8);
    public final IPicker a;

    public n1(IPicker iPicker) {
        this.a = iPicker;
    }

    public void onActivityCreated(Activity activity, Bundle bundle) {
        g.add(Integer.valueOf(activity.hashCode()));
    }

    public void onActivityDestroyed(Activity activity) {
        g.remove(Integer.valueOf(activity.hashCode()));
    }

    public void onActivityPaused(Activity activity) {
        a0 a0Var = c;
        if (a0Var != null) {
            e = a0Var.k;
            long currentTimeMillis = System.currentTimeMillis();
            d = currentTimeMillis;
            a0 a0Var2 = c;
            a0 a0Var3 = (a0) a0Var2.clone();
            a0Var3.a = currentTimeMillis;
            currentTimeMillis -= a0Var2.a;
            if (currentTimeMillis >= 0) {
                a0Var3.i = currentTimeMillis;
            } else {
                m0.b(null);
            }
            s1.a(a0Var3);
            c = null;
            if (!activity.isChild()) {
                f = null;
            }
        }
    }

    public void onActivityResumed(Activity activity) {
        long currentTimeMillis = System.currentTimeMillis();
        String name = activity.getClass().getName();
        String str = e;
        a0 a0Var = new a0();
        String str2 = "";
        if (TextUtils.isEmpty(str2)) {
            a0Var.k = name;
        } else {
            a0Var.k = a.E(name, ":", str2);
        }
        a0Var.a = currentTimeMillis;
        a0Var.i = -1;
        if (str == null) {
            str = str2;
        }
        a0Var.j = str;
        s1.a(a0Var);
        c = a0Var;
        a0Var.l = g.remove(Integer.valueOf(activity.hashCode())) ^ 1;
        if (!activity.isChild()) {
            try {
                activity.getWindow().getDecorView().hashCode();
                f = activity;
            } catch (Exception e) {
                m0.b(e);
            }
        }
    }

    public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
    }

    public void onActivityStarted(Activity activity) {
        int i = b + 1;
        b = i;
        if (i == 1) {
            IPicker iPicker = this.a;
            if (iPicker != null) {
                iPicker.show(true);
            }
        }
    }

    public void onActivityStopped(Activity activity) {
        if (e != null) {
            int i = b - 1;
            b = i;
            if (i <= 0) {
                e = null;
                d = 0;
                IPicker iPicker = this.a;
                if (iPicker != null) {
                    iPicker.show(false);
                }
            }
        }
    }
}
